extends Control

@export var slot: VBoxContainer

var _pool: Array[Button]
var _sbtns: Array[Button]

func make_selections(s: Dictionary):
	clear()
	for selection in s:
		var btn := obtain_btn()
		btn.size_flags_vertical = Control.SIZE_EXPAND_FILL
		btn.text = selection
		btn.button_up.connect(s[selection] as Callable, CONNECT_ONE_SHOT)
		_sbtns.push_back(btn)
		slot.add_child(btn)


func clear():
	for btn in _sbtns:
		slot.remove_child(btn)
		_pool.push_back(btn)
	_sbtns.clear()


func obtain_btn() -> Button:
	if _pool.size() > 0:
		return _pool.pop_back()
	else:
		return Button.new()
